package org.theqcp.wow.sim.engine.old;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.theqcp.wow.model.player.classes.shaman.Shaman;
import org.theqcp.wow.sim.engine.old.core.Effect;
import org.theqcp.wow.sim.engine.revised.EquipmentPointConfig;
import org.theqcp.wow.sim.engine.revised.EquipmentPointConfig.Method;

@SuppressWarnings( "unused" )
@Deprecated
public class EnhSimConfigDeprecated {

    public static final double EXPERTISE_RATING_TO_EXPERTISE = 8.1974973675;
    public static final int BLESSING_OF_WISDOM_MP5 = 91;
    public static final int WATER_SHIELD_MP5 = 100;
    public static final int MANA_SPRING_MP5 = 85;
    public static final int EPTEST_COUNT = 14;

    protected final Logger log = LogManager.getLogger(getClass().getSimpleName());

    protected final HashSet<Statistics> statsSet = new HashSet<Statistics>();
    protected final HashSet<EnhSim> enhsimSet = new HashSet<EnhSim>();

    protected final ArrayList<Effect> rotationList = new ArrayList<Effect>();
    protected final HashSet<Effect> effectsSet = new HashSet<Effect>();

    protected EquipmentPointConfig epConfig = null;

    protected boolean simulate_mana_ = true;

    protected int threads_ = 1;

    private int lagMax;
    private int lagMin;
    private boolean oh_attack;
    private boolean mh_attack;
    private Shaman player;

    public EnhSimConfigDeprecated(Shaman player) {
	this.player = player;
    }

    public void setEPConfig( EquipmentPointConfig epConfig ) {
	this.epConfig = epConfig;
    }

    public void setEP( int ep_precision, boolean ep_base_stat, int ep_ap, int ep_crit_rating, int ep_hit_rating,
	    int ep_expertise, int ep_haste_rating, int ep_armor_penetration_rating, int ep_spellpower, double ep_dps,
	    int ep_mana, int ep_spirit, int ep_mp5 ) {
	if( epConfig == null ) {
	    epConfig = new EquipmentPointConfig();
	}

	epConfig.setPrecision(ep_precision);
	epConfig.setMethodBase(Method.valueOf(String.valueOf(ep_base_stat)));
	epConfig.setAttackPower(ep_ap);
	epConfig.setCritRating(ep_crit_rating);
	epConfig.setHitRating(ep_hit_rating);
	epConfig.setExpertise(ep_expertise);
	epConfig.setHasteRating(ep_haste_rating);
	epConfig.setArmorPenetrationRating(ep_armor_penetration_rating);
	epConfig.setSpellPower(ep_spellpower);
	epConfig.setDps(ep_dps);
	epConfig.setMana(ep_mana);
	epConfig.setSpirit(ep_spirit);
	epConfig.setMp5(ep_mp5);
    }

    public void setThreads( int count ) {
	this.threads_ = count;

	if( epConfig != null ) {
	    count = EPTEST_COUNT;
	}

	enhsimSet.clear();
	statsSet.clear();

	for( int i = 0; i < count; i++ ) {
	    Statistics statistics = new Statistics();
	    enhsimSet.add(new EnhSim(player, statistics));
	    statsSet.add(statistics);
	}
    }

    public void setLag( int min, int max ) {
	min /= 10;
	max /= 10;
	if( max <= 1 )
	    max = 2;
	if( max <= min )
	    max = min + 1;
	if( min < 1 )
	    min = 1;

	this.lagMin = min;
	this.lagMax = max;
    }

    public void setSimulateMana( boolean simulate_mana ) {
	this.simulate_mana_ = simulate_mana;

	if( !simulate_mana_ && (epConfig != null) ) {
	    epConfig.setSpirit(0);
	    epConfig.setMana(0);
	    epConfig.setMp5(0);
	}

	if( simulate_mana_ ) {
	    // addEffect(new Effect.ManaRegen());
	}
    }

    public void setConfig( HashMap<String, String> config ) {
	/*
	 * if( epConfig != null ) { setEP(atoi(config.get("ep_precision")),
	 * config.get("ep_base_stat").equalsIgnoreCase("ap"),
	 * atoi(config.get("ep_ap")), atoi(config.get("ep_crit_rating")),
	 * atoi(config.get("ep_hit_rating")), atoi(config.get("ep_expertise")),
	 * atoi(config.get("ep_haste_rating")),
	 * atoi(config.get("ep_armor_penetration_rating")),
	 * atoi(config.get("ep_spellpower")), atof(config.get("ep_dps")),
	 * atoi(config.get("ep_mana")), atoi(config.get("ep_spirit")),
	 * atoi(config.get("ep_mp5"))); }
	 * 
	 * setThreads(atoi(config.get("threads")));
	 * 
	 * setLag(atoi(config.get("min_lag")), atoi(config.get("max_lag")));
	 * setSimulateMana(atoi(config.get("simulate_mana")) == 1);
	 * 
	 * setImbue(Slot.MAINHAND, config.get("mh_imbue"));
	 * setEnchant(Slot.MAINHAND, config.get("mh_enchant"));
	 * setWeaponType(Slot.MAINHAND, config.get("mh_weapon"));
	 * setDPS(Slot.MAINHAND, getConfigFloat("mh_dps"));
	 * setSpeed(Slot.MAINHAND, getConfigFloat("mh_speed"));
	 * 
	 * setImbue(Slot.OFFHAND, config.get("oh_imbue"));
	 * setEnchant(Slot.OFFHAND, config.get("oh_enchant"));
	 * setWeapon(Slot.OFFHAND, config.get("oh_weapon"));
	 * setDPS(Slot.OFFHAND, getConfigFloat("oh_dps"));
	 * setSpeed(Slot.OFFHAND, getConfigFloat("oh_speed"));
	 * 
	 * setCrit(getConfigFloat("mh_crit")); setHit(getConfigFloat("mh_hit"));
	 * setExpertiseRating(getConfigFloat("mh_expertise_rating"));
	 * 
	 * setRace(config.get("race"));
	 * 
	 * int rotation_count = getConfigInt("rotation_priority_count"); //
	 * setRotationCount(rotation_count);
	 * 
	 * for( int i = 0; i < rotation_count; ++i ) {
	 * addRotationEvent(config.get("rotation_priority" + i)); }
	 * 
	 * setRotationSettings(getConfigInt("mh_auto_attack") == 1,
	 * getConfigInt("oh_auto_attack") == 1,
	 * getConfigInt("cast_ll_only_if_wf_on_cd") == 1,
	 * getConfigInt("cast_lvb_only_if_fsdots_left"),
	 * getConfigInt("cast_lvb_only_if_fs_active") == 1,
	 * getConfigFloat("wait_mw_if_lvb_cd_left"),
	 * getConfigInt("cast_fs_only_if_dots_left"),
	 * getConfigInt("cast_ls_only_if_charges_left"),
	 * getConfigFloat("cast_sr_only_if_mana_left"));
	 * 
	 * addTrinket(config.get("trinket1"));
	 * addTrinket(config.get("trinket2"));
	 * 
	 * setTotem(config.get("totem"));
	 * 
	 * // setSetBonus(config["set_bonus"]); //
	 * setMetagem(config["metagem"]);
	 * 
	 * addGlyph(config.get("glyph_major1"));
	 * addGlyph(config.get("glyph_major2"));
	 * addGlyph(config.get("glyph_major3")); //
	 * addGlyph(config.get("glyph_major4"));
	 * addGlyph(config.get("glyph_minor1"));
	 * addGlyph(config.get("glyph_minor2"));
	 * addGlyph(config.get("glyph_minor3"));
	 * 
	 * setAttackPower(getConfigInt("ap"));
	 * setHaste(getConfigFloat("haste"));
	 * setArmorPenetration(getConfigFloat("armor_penetration"));
	 * 
	 * setStength(getConfigInt("str")); setAgility(getConfigInt("agi"));
	 * setIntelligence(getConfigInt("int")); setSpirit(getConfigInt("spi"));
	 * 
	 * setMiss(getConfigFloat("miss")); setDodge(getConfigFloat("dodge"));
	 * setGlancing(getConfigFloat("glancing"));
	 * setSpellMiss(getConfigFloat("spell_miss"));
	 * setArmor(getConfigInt("armor"));
	 * 
	 * setNatureResistance(getConfigInt("nature_resistance"));
	 * setFireResistance(getConfigInt("fire_resistance"));
	 * setFrostResistance(getConfigInt("frost_resistance"));
	 * setArcanaResistance(getConfigInt("arcane_resistance"));
	 * setShadowResistance(getConfigInt("shadow_resistance"));
	 * 
	 * setSpellpower(getConfigInt("spellpower"));
	 * setSpellCrit(getConfigFloat("spell_crit"));
	 * setSpellHit(getConfigFloat("spell_hit"));
	 * setMaxMana(getConfigFloat("max_mana")); setMp5(getConfigInt("mp5"));
	 * 
	 * setBuff("attack_power_buff_multiplier",
	 * getConfigBuff("attack_power_buff_multiplier"));
	 * setBuff("spell_crit_chance_buff",
	 * getConfigBuff("spell_crit_chance_buff"));
	 * 
	 * setTalent("flurry", getConfigTalent("flurry"));
	 * setTalent("elemental_weapons", getConfigTalent("elemental_weapons"));
	 * setTalent("mental_quickness", getConfigTalent("mental_quickness"));
	 * setTalent("mental_dexterity", getConfigTalent("mental_dexterity"));
	 * setTalent("ancestral_knowledge",
	 * getConfigTalent("ancestral_knowledge"));
	 * setTalent("shamanistic_focus", getConfigTalent("shamanistic_focus"));
	 * setTalent("weapon_mastery", getConfigTalent("weapon_mastery"));
	 * setTalent("dual_wield_specialization",
	 * getConfigTalent("dual_wield_specialization"));
	 * setTalent("improved_stormstrike",
	 * getConfigTalent("improved_stormstrike")); setTalent("unleashed_rage",
	 * getConfigTalent("unleashed_rage")); setTalent("improved_shields",
	 * getConfigTalent("improved_shields")); setTalent("static_shock",
	 * getConfigTalent("static_shock")); // setTalent("shamanistic_rage", //
	 * getConfigTalent("shamanistic_rage")); setTalent("maelstrom_weapon",
	 * getConfigTalent("maelstrom_weapon")); setTalent("concussion",
	 * getConfigTalent("concussion")); setTalent("convection",
	 * getConfigTalent("convection")); setTalent("call_of_flame",
	 * getConfigTalent("call_of_flame")); setTalent("call_of_thunder",
	 * getConfigTalent("call_of_thunder")); setTalent("unrelenting_storm",
	 * getConfigTalent("unrelenting_storm")); setTalent("reverberation",
	 * getConfigTalent("reverberation")); setTalent("elemental_devastation",
	 * getConfigTalent("elemental_devastation"));
	 * setTalent("elemental_focus", getConfigTalent("elemental_focus"));
	 * setTalent("elemental_fury", getConfigTalent("elemental_fury"));
	 * setTalent("elemental_precision",
	 * getConfigTalent("elemental_precision"));
	 * setTalent("lightning_mastery", getConfigTalent("lightning_mastery"));
	 * setTalent("elemental_oath", getConfigTalent("elemental_oath"));
	 * setTalent("lightning_overload",
	 * getConfigTalent("lightning_overload")); setTalent("lava_flows",
	 * getConfigTalent("lava_flows")); setTalent("storm_earth_and_fire",
	 * getConfigTalent("storm_earth_and_fire"));
	 * 
	 * // fixStats();
	 * 
	 * setBuff("armor_debuff_major", getConfigBuff("armor_debuff_major"));
	 * setBuff("armor_debuff_minor", getConfigBuff("armor_debuff_minor"));
	 * setBuff("physical_vulnerability_debuff",
	 * getConfigBuff("physical_vulnerability_debuff"));
	 * setBuff("melee_haste_buff", getConfigBuff("melee_haste_buff"));
	 * setBuff("melee_crit_chance_buff",
	 * getConfigBuff("melee_crit_chance_buff"));
	 * setBuff("attack_power_buff_flat",
	 * getConfigBuff("attack_power_buff_flat")); setBuff("spell_haste_buff",
	 * getConfigBuff("spell_haste_buff"));
	 * setBuff("spell_crit_chance_debuff",
	 * getConfigBuff("spell_crit_chance_debuff"));
	 * setBuff("spell_damage_debuff", getConfigBuff("spell_damage_debuff"));
	 * setBuff("spellpower_buff", getConfigBuff("spellpower_buff"));
	 * setBuff("spell_hit_chance_debuff",
	 * getConfigBuff("spell_hit_chance_debuff")); setBuff("haste_buff",
	 * getConfigBuff("haste_buff")); setBuff("percentage_damage_increase",
	 * getConfigBuff("percentage_damage_increase"));
	 * setBuff("crit_chance_debuff", getConfigBuff("crit_chance_debuff"));
	 * setBuff("stat_multiplier", getConfigBuff("stat_multiplier"));
	 * setBuff("stat_add_buff", getConfigBuff("stat_add_buff"));
	 * setBuff("agi_and_strength_buff",
	 * getConfigBuff("agi_and_strength_buff")); setBuff("intellect_buff",
	 * getConfigBuff("intellect_buff")); setBuff("replenishment",
	 * getConfigInt("replenishment")); setBuff("water_shield",
	 * getConfigInt("water_shield")); setBuff("mana_spring_totem",
	 * getConfigInt("mana_spring_totem")); setBuff("blessing_of_wisdom",
	 * getConfigInt("blessing_of_wisdom")); setBuff("judgement_of_wisdom",
	 * getConfigInt("judgement_of_wisdom"));
	 */

	/*
	 * setConsumable(config.get("flask_elixir"));
	 * setConsumable(config.get("guardian_elixir"));
	 * setConsumable(config.get("potion"));
	 * setConsumable(config.get("food"));
	 * setMiscItem(config.get("misc_item"));
	 * 
	 * 
	 * 
	 * 
	 * 
	 * setUseManaPotionMaxMana(getConfigFloat("use_mana_potion_if_mana_left"
	 * ));
	 * 
	 * setCombatLength(getConfigFloat("combat_length"));
	 * setWaitSSWithWFCD(getConfigFloat("wait_ss_with_wf_cd")); //
	 * useSearingTotem(getConfigInt("use_searing_totem"));
	 * setBloodlust(getConfigInt("bloodlust_casters"),
	 * getConfigInt("sync_bloodlust_with_trinkets"));
	 */
    }

    private static int getTalentRank( String value ) {
	return Integer.valueOf(getBoundedValue(value));
    }

    private static float getBuffValue( String value ) {
	return Float.valueOf(getBoundedValue(value));
    }

    private static String getBoundedValue( String value ) {
	StringTokenizer st = new StringTokenizer(value, "/");

	if( st.countTokens() > 0 ) {
	    value = st.nextToken();
	}

	return value;
    }

    /**
     * Convenience function for converting a string to an int
     * 
     * @param value
     * @return
     */
    private static int atoi( String value ) {
	return Integer.valueOf(value);
    }

    /**
     * Convenience function for converting a string to a float
     * 
     * @param value
     * @return
     */
    private static float atof( String value ) {
	return Float.valueOf(value);
    }

}
